//
//  PGFlipViewController.m
//  PhotographicGuide
//
//  Created by indream on 13-2-10.
//  Copyright (c) 2013年 indream. All rights reserved.
//

#import "PGFlipViewController.h"
#import "PGDetailViewController.h"
#import "MobClick.h"
#import "PGFavoriteViewController.h"
#import "PGArticle.h"
#import "PGArticleManager.h"
#import "PGLocalFileManager.h"
#import "PGWebViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "UMSocialControllerService.h"
#import "UMSocialAccountManager.h"
#import "UMSocial.h"
@interface PGFlipViewController ()

@end

@implementation PGFlipViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        [[NSBundle mainBundle] loadNibNamed:@"PGFlipViewController" owner:self options:nil];
    }else{
        [[NSBundle mainBundle] loadNibNamed:@"PGFlipViewController_iPad" owner:self options:nil];
    }
    isShowScale = NO;
    isShowAnimate = NO;
    [self initFrame];
}
-(void)viewDidUnload{
    [self setShareView:nil];
    
    [_imageViewScreen removeFromSuperview];
    [_viewScreen removeFromSuperview];
    [_backgroundViewScreen removeFromSuperview];
    _imageViewScreen = nil;
    _viewScreen = nil;
    _backgroundViewScreen = nil;
}
-(void)initFrame{
    screen_offset = SCREEN_HEIGHT==568.0?30:(SCREEN_HEIGHT==768?5:20);
    _backgroundViewScreen = [[UIView alloc]initWithFrame:self.view.frame];
    _viewScreen = [[UIView alloc]initWithFrame:self.view.bounds];
    _imageViewScreen = [[UIImageView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_backgroundViewScreen];
    [_backgroundViewScreen addSubview:_viewScreen];
    [_viewScreen addSubview:_imageViewScreen];
    [_backgroundViewScreen setUserInteractionEnabled:NO];
    [_viewScreen setUserInteractionEnabled:NO];
    [_imageViewScreen setUserInteractionEnabled:NO];
}
-(void)viewDidAppear:(BOOL)animated{
    if(_backgroundViewScreen){
        [_backgroundViewScreen setFrame:self.view.frame];
        [_viewScreen setFrame:self.view.frame];
        [_imageViewScreen setFrame:self.view.frame];
    }
    [super viewDidAppear:animated];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - flip method
-(void)timerFadInHandle:(NSTimer*)timer{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        scale-=0.008;
        oy3 -= (oy3+screen_offset*SCREEN_SCALE)*0.2;
        if(scale>0.94){
            rot1 -= (rot1-15)*0.1;
        }
        if(scale<0.95){
            rot2 -= (rot2+rot1)*0.3;
            if(scale<0.901){
                if(rot2<=-rot1+0.1){
                    rot2 = -rot1;
                    scale = 0.9;
                    [timer invalidate];
                    isShowScale = YES;
                    isShowAnimate = NO;
                }
            }
        }
    }else{
        scale-=0.006;
        oy3 -= (oy3+screen_offset*SCREEN_SCALE)*0.001;
        if(scale>0.98){
            rot1 -= (rot1-5)*0.1;
        }
        if(scale<0.977){
            rot2 -= (rot2+rot1)*0.3;
            if(scale<0.956){
                if(rot2<=-rot1+0.1){
                    rot2 = -rot1;
                    scale = 0.955;
                    [timer invalidate];
                    isShowScale = YES;
                    isShowAnimate = NO;
                }
            }
        }
    }
    CALayer *layer1 = _imageViewScreen.layer;
    layer1.transform = CATransform3DMakeRotationWithAxisY(rot1,oy1,0,oz1);
    CALayer *layer2 = _viewScreen.layer;
    layer2.transform = CATransform3DMakeRotationWithAxisY(rot2,oy2,oy3,0);
}
-(void)timerFadOutHandle:(NSTimer*)timer{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        scale+=0.008;
        rot2 -= rot2*0.3;
        oy3 -= oy3*0.27;
        if(scale>0.94){
            rot1 -= rot1*0.3;
            if(scale>0.99){
                scale = 1.0;
                if(rot1<=0.1){
                    rot2 = 0;
                    rot1 = 0.0;
                    oz1 = 0.0;
                    oz2 = 0.0;
                    oy3 = 0.0;
                    [timer invalidate];
                    isShowAnimate = NO;
                    [_imageViewScreen setImage:nil];
                    [_backgroundViewScreen setBackgroundColor:[UIColor clearColor]];
                }
            }
        }
    }else{
        scale+=0.006;
        rot2 -= rot2*0.3;
        oy3 -= oy3*0.27;
        if(scale>0.98){
            rot1 -= rot1*0.3;
            if(scale>0.99){
                scale = 1.0;
                if(rot1<=0.1){
                    rot2 = 0;
                    rot1 = 0.0;
                    oz1 = 0.0;
                    oz2 = 0.0;
                    oy3 = 0.0;
                    [timer invalidate];
                    isShowAnimate = NO;
                    [_imageViewScreen setImage:nil];
                    [_backgroundViewScreen setBackgroundColor:[UIColor clearColor]];
                }
            }
        }
    }
    CALayer *layer1 = _imageViewScreen.layer;
    layer1.transform = CATransform3DMakeRotationWithAxisY(rot1,oy1,0,oz1);
    CALayer *layer2 = _viewScreen.layer;
    layer2.transform = CATransform3DMakeRotationWithAxisY(rot2,oy2,oy3,0);
}
-(void)addScreenFadin{
    isShowAnimate = YES;
    [_backgroundViewScreen setUserInteractionEnabled:YES];
    rot1 = 0.0;
    oz1 = 0.0;
    
    rot2 = 0.0;
    oz2 = 0.0;
    oy1 = -SCREEN_HEIGHT/2;
    oy2 = SCREEN_HEIGHT/2;
    
    scale = 1.0;
    
    [_imageViewScreen setImage:[self screenImage]];
    [_backgroundViewScreen setBackgroundColor:[UIColor blackColor]];
    [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(timerFadInHandle:) userInfo:nil repeats:YES];
}
-(void)addScreenFadout{
    isShowAnimate = YES;
    [_backgroundViewScreen setUserInteractionEnabled:NO];
    [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(timerFadOutHandle:) userInfo:nil repeats:YES];
    [UIView beginAnimations:@"ShareViewAnimation" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(theAnimationStop:finish:context:)];
    _shareView.center = CGPointMake(160.0, self.view.bounds.size.height+_shareView.bounds.size.height/2);
    [UIView commitAnimations];
}
- (void)theAnimationStop:(NSString *)animation finish:(BOOL)flag context:(void *)context
{
    [_shareView removeFromSuperview];
}
-(void)addShareView:(int)articleId{
    _shareView.articleId = articleId;
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        [self addScreenFadin];
        [self.view addSubview:_shareView];
        [_shareView setCenter:CGPointMake(160.0, self.view.bounds.size.height+_shareView.bounds.size.height/2)];
        [UIView beginAnimations:@"ShareViewAnimation" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.3];
        _shareView.center = CGPointMake(160.0, self.view.bounds.size.height-_shareView.bounds.size.height/2);
        [UIView commitAnimations];
    }else{
        [self.view addSubview:_shareView];
        [_backgroundViewScreen setUserInteractionEnabled:YES];
        [_shareView setCenter:CGPointMake(584, 160)];
        _shareView.alpha = 0;
        [UIView beginAnimations:@"ShareViewAnimation" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.3];
        _shareView.center = CGPointMake(584, 180);
        _shareView.alpha = 1.0;
        [UIView commitAnimations];
        isShowAnimate=NO;
        isShowScale=YES;
    }
   
}

- (IBAction)doneHandle:(id)sender {
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        [self addScreenFadout];
    }else{
        
        [_backgroundViewScreen setUserInteractionEnabled:NO];
        [_shareView setCenter:CGPointMake(584, 180)];
        _shareView.alpha = 1.0;
        [UIView beginAnimations:@"ShareViewAnimation" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.3];
        _shareView.center = CGPointMake(584, 160.0);
        _shareView.alpha = 0.0;
        [UIView commitAnimations];
    }
}

- (IBAction)openFavoriteList:(id)sender {
    PGFavoriteViewController *controller = [[PGFavoriteViewController alloc]init];
    [self.navigationController pushViewController:controller animated:YES];
}

- (IBAction)openShareList:(id)sender {
    [MobClick event:@"Share"];
    UMSocialData *socialData = [[UMSocialData alloc] initWithIdentifier:@"UMSocialSDK" withTitle:nil];
    if([PGArticleManager sharedManager].currentArticleId>0){
        PGArticle*article = [[PGArticleManager sharedManager]articleWithID:[PGArticleManager sharedManager].currentArticleId];
        socialData.shareText = [NSString stringWithFormat:@"#星空摄影#%@ 作者介绍：%@ 下载地址：%@",article.desc,article.authorUrl?article.authorUrl:@"http://url.cn/DVsEEK",@"http://url.cn/DVsEEK"];
        if([[PGLocalFileManager sharedManager]fileIsExist:article.imageLarge]){
            socialData.shareImage = [UIImage imageWithData:[[PGLocalFileManager sharedManager]fileWithURL:article.imageLarge]];
        }else{
            if([[PGLocalFileManager sharedManager]fileIsExist:article.imageSmall]){
                socialData.shareImage = [UIImage imageWithData:[[PGLocalFileManager sharedManager]fileWithURL:article.imageSmall]];
            }
        }
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = article.authorUrl;
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:@"511c8adf52701536e900001a"
                                          shareText:[NSString stringWithFormat:@"#星空摄影#%@ 作者介绍：%@ 下载地址：%@",article.desc,article.authorUrl?article.authorUrl:@"http://url.cn/DVsEEK",@"http://url.cn/DVsEEK"]
                                         shareImage:[UIImage imageWithData:[[PGLocalFileManager sharedManager]fileWithURL:article.imageSmall]]
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToWechatSession,UMShareToWechatTimeline,nil]
                                           delegate:nil];
//        UMSocialControllerService *socialController = [[UMSocialControllerService alloc] initWithUMSocialData:socialData];
//        socialController.socialUIDelegate = self;
//        //    [UMSocialControllerService setSocialConfigDelegate:self];
//        [self presentModalViewController:[socialController getSocialShareListController] animated:YES];
    }else{
//        socialData.shareText = @"#星空摄影#是进阶天文摄影的必备应用，星空摄影收录了全球各地爱好者的优秀星空照片和天文作品。体验网址 - http://url.cn/DVsEEK";
//        UMSocialControllerService *socialController = [[UMSocialControllerService alloc] initWithUMSocialData:socialData];
//        [self presentModalViewController:[socialController getSnsAccountController] animated:YES];
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:@"511c8adf52701536e900001a"
                                          shareText:@"#星空摄影#是进阶天文摄影的必备应用，星空摄影收录了全球各地爱好者的优秀星空照片和天文作品。体验网址 - http://url.cn/DVsEEK"
                                         shareImage:nil
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToWechatSession,UMShareToWechatTimeline,nil]
                                           delegate:nil];
    }
}

- (IBAction)openPersonalCenter:(id)sender {
    
    UMSocialData *socialData = [[UMSocialData alloc] initWithIdentifier:@"UMSocialSDK" withTitle:nil];
    UMSocialControllerService *socialController = [[UMSocialControllerService alloc] initWithUMSocialData:socialData];
    UMSocialAccountEntity *account = [[UMSocialAccountManager socialAccountDictionary]objectForKey:@"loginAccount"];
    NSLog(@"%@",account.userName);
    NSLog(@"%@",account.usid);
//    [[UMSocialDataService defaultDataService] requestUnBindToSnsWithCompletion:nil];
    socialController.socialUIDelegate = self;

    [self presentModalViewController:[socialController getSocialAccountController] animated:YES];
}
- (IBAction)presentAppStoreForInstall:(id)sender{
    if([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"com.xeecos.timerweather://"]]){
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"com.xeecos.timerweather://"]];
        [MobClick event:@"OpenTimerweather"];
    }else{
        [MobClick event:@"Install"];
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/qing-tian-zhong/id423977365?mt=8"]];
        //[self openAppStoreWithID:@"423977365" withURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/qing-tian-zhong/id423977365?mt=8"]];
    }
}

- (IBAction)openContactUs:(id)sender {
    PGWebViewController *controller = [[PGWebViewController alloc]init];
    controller.url = @"http://1.starrynightwalk.sinaapp.com/?page_id=82";
    controller.title = @"星空摄影投稿";
    [self.navigationController pushViewController:controller animated:YES];
}
- (IBAction)presentAppStoreForReview:(id)sender
{
    [MobClick event:@"Review"];
    
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=603391855&type=Purple+Software"]];
    //[self openAppStoreWithID:@"603391855" withURL:[NSURL URLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=603391855&type=Purple+Software"]];
}
-(void)openAppStoreWithID:(NSString*)appStoreID withURL:(NSURL*)appStoreURL{
    if(NSClassFromString(@"SKStoreProductViewController")) { // Checks for iOS 6 feature.
        
        SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
        storeController.delegate = self; // productViewControllerDidFinish
        
        // Example app_store_id (e.g. for Words With Friends)
        // [NSNumber numberWithInt:322852954];
        NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier : appStoreID };
        
        
        [storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
            if (result) {
                [self presentViewController:storeController animated:YES completion:nil];
            } else {
                [[[UIAlertView alloc] initWithTitle:@"Uh oh!" message:@"There was a problem displaying the app" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil] show];
            }
        }];
        
        
    } else { // Before iOS 6, we can only open the URL
        [[UIApplication sharedApplication] openURL:appStoreURL];
    }
}
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
    [self dismissModalViewControllerAnimated:YES];
}
-(UIImage*)screenImage{
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //    CGSize imageSizeWithBorder = CGSizeMake([image size].width*SCREEN_SCALE, [image size].height*SCREEN_SCALE);
    //    UIGraphicsBeginImageContext(imageSizeWithBorder);
    //    [image drawInRect:(CGRect){{2,2}, {image.size.width*SCREEN_SCALE-4,image.size.height*SCREEN_SCALE-4}}];
    //    image = UIGraphicsGetImageFromCurrentImageContext();
    //    UIGraphicsEndImageContext();
    return image;
}
CATransform3D CATransform3DMakeRotationWithAxisY(float angle,float offsetY,float offsetY2,float offsetZ){
    CATransform3D rotateT = CATransform3DMakeRotation(DEGREES_TO_RADIANS(angle), 1, 0, 0);
    CATransform3D transT = CATransform3DMakeTranslation(0.0, offsetY, 0.0);
    CATransform3D transT2 = CATransform3DMakeTranslation(0.0,-offsetY,0.0);
    
    CATransform3D scaleT = CATransform3DMakeTranslation(0.0,offsetY2,offsetZ);
    return CATransform3DPerspect(CATransform3DConcat(CATransform3DConcat(CATransform3DConcat(transT, rotateT),transT2), scaleT), CGPointMake(0, 0.0), 300);
}
CATransform3D CATransform3DMakePerspective(CGPoint center, float disZ)
{
    CATransform3D transToCenter = CATransform3DMakeTranslation(-center.x, -center.y, 0);
    CATransform3D transBack = CATransform3DMakeTranslation(center.x, center.y, 0);
    CATransform3D scale = CATransform3DIdentity;
    scale.m34 = -1.0f/disZ;
    return CATransform3DConcat(CATransform3DConcat(transToCenter, scale), transBack);
}
CATransform3D CATransform3DPerspect(CATransform3D t, CGPoint center, float disZ)
{
    return CATransform3DConcat(t, CATransform3DMakePerspective(center, disZ));
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    if(isShowAnimate==NO&&isShowScale==YES){
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
            [self addScreenFadout];
        }else{
            [self doneHandle:nil];
        }
    }
}

#pragma mark - UMSocialUIDelegate
-(void)didCloseUIViewController:(UMSViewControllerType)fromViewControllerType
{
    NSLog(@"didCloseUIViewController with type is %d",fromViewControllerType);
}

-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    NSLog(@"didFinishGetUMSocialDataInViewController is %@",response);
}
-(void)didFinishGetUMSocialDataResponse:(UMSocialResponseEntity *)response{
    
}
#pragma mark - UMSocialConfigDelegate
-(UITableViewCell *)customCellForShareListTableView
{
    UITableViewCell *weiXinCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"weixinCell"] ;
    weiXinCell.textLabel.text = @"微信分享";
    weiXinCell.imageView.image = [UIImage imageNamed:@"UMSocialSDKResources.bundle/UMS_weixin_icon.png"];
    return weiXinCell;
}
- (NSArray *)shareToPlatforms{
    NSArray *shareToArray = @[@[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSina,UMShareToTencent,UMShareToQzone,UMShareToRenren,UMShareToDouban],@[UMShareToEmail,UMShareToSms]];
    return shareToArray;
}
-(void)didSelectShareListTableViewCell:(UITableView *)tableView
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"分享到微信" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"分享到会话",@"分享到朋友圈",nil];
    [actionSheet showInView:tableView];
    
    NSLog(@"分享到微信");
}
//设置官方微博，只支持新浪微博和腾讯微博
-(NSDictionary *)followSnsUids
{
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"2958354881",UMShareToSina,@"starrynightwalk",UMShareToTencent,nil];
    return dictionary;
}
-(UMSocialSnsPlatform *)socialSnsPlatformWithSnsName:(NSString *)snsName
{
    UMSocialSnsPlatform *customSnsPlatform = [[UMSocialSnsPlatform alloc] initWithPlatformName:snsName];
    if ([snsName isEqualToString:UMShareToWechatSession]||[snsName isEqualToString:UMShareToWechatTimeline]) {
        customSnsPlatform.bigImageName = @"UMSocialSDKResources.bundle/UMS_wechart_icon";
        customSnsPlatform.smallImageName = @"UMSocialSDKResources.bundle/UMS_wechart_on.png";
        customSnsPlatform.displayName = @"微信分享";
        customSnsPlatform.loginName = @"微信账号";
        customSnsPlatform.snsClickHandler = ^(UIViewController *presentingController, UMSocialControllerService * socialControllerService, BOOL isPresentInController){
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"分享到微信" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"分享到会话",@"分享到朋友圈",nil];
            [actionSheet showInView:presentingController.view];
        };
    }
    return customSnsPlatform;
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 2) {
        return;
    }
    
    if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]) {
        
        SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
        

        
        /*下面实现图片分享，只能分享文字或者分享图片，或者分享url，里面带有图片缩略图和描述文字 */
         WXMediaMessage * message = [WXMediaMessage message];
        if([PGArticleManager sharedManager].currentArticleId>0){
            
            WXWebpageObject *ext = [WXWebpageObject object];
            PGArticle*article = [[PGArticleManager sharedManager]articleWithID:[PGArticleManager sharedManager].currentArticleId];
            [message setTitle:article.name];
            [message setDescription:article.desc];
            
            UIImage*thumb = [self cropImage:[UIImage imageWithData:[[PGLocalFileManager sharedManager]fileWithURL:article.imageSmall]] withSize:CGSizeMake(90, 60)];
            message.thumbData = UIImageJPEGRepresentation(thumb,50.0);
            ext.webpageUrl = @"https://itunes.apple.com/cn/app/xing-kong-she-ying/id603391855?ls=1&mt=8";
            message.mediaObject = ext;
        }else{
            WXWebpageObject *ext = [WXWebpageObject object];
            ext.webpageUrl = @"https://itunes.apple.com/cn/app/xing-kong-she-ying/id603391855?ls=1&mt=8";
            [message setTitle:@"星空摄影"];
            [message setDescription:@"进阶天文摄影的必备应用，星空摄影收录了全球各地爱好者的优秀星空照片和相关的天文作品。"];
            message.thumbData = UIImageJPEGRepresentation([UIImage imageNamed:@"icon.png"], 80.0);
            message.mediaObject = ext;
        }
         req.message = message;
         req.bText = NO;
        
        
        if (buttonIndex == 0) {
            req.scene = WXSceneSession;
        }
        if (buttonIndex == 1) {
            req.scene = WXSceneTimeline;
        }
        [WXApi sendReq:req];
    }
    else{
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您的设备没有安装微信" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
        [alertView show];
    }
}
-(UIImage*)cropImage:(UIImage*)image withSize:(CGSize)size{
    UIGraphicsBeginImageContext(CGSizeMake(size.width, size.height));
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return result;
}
@end
